package 第三题;

/**
 * ClassName: lettercount
 * Package: 第三题
 * Description:编写程序，统计出字符串“want you to know one thing”中字母n和字母o的出现次数
 *
 * @Author fjorid
 * @Create 2025/1/11 20:51
 * @Version 1.0
 */
 class LetterCount {
    public static void main(String[] args) {
        String str = "want you to know one thing";
        int countN = 0;
        int countO = 0;


        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            // 判断字符是否为字母n
            if (ch == 'n') {
                countN++;
            }
            // 判断字符是否为字母o
            else if (ch == 'o') {
                countO++;
            }
        }

        // 输出字母n和字母o的出现次数
        System.out.println("字母n的出现次数：" + countN);
        System.out.println("字母o的出现次数：" + countO);
    }
}
